package com.bamboo.eduservice.controller;


import com.bamboo.commonutils.ResponseEntity;
import com.bamboo.eduservice.entity.subject.OneSubject;
import com.bamboo.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author jack.wu
 * @since 2020-07-04
 */
@Api(description = "课程分类管理")
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {

    @Resource
    private EduSubjectService subjectService;

    @ApiOperation(value = "读取上传过来excel并解析到数据库中")
    @PostMapping("add")
    public ResponseEntity saveSubject(MultipartFile file){
        subjectService.saveSubject(file, subjectService);
        return ResponseEntity.ok();
    }

    @ApiOperation(value = "查询所有课程分类使用树形结构")
    @GetMapping("list")
    public ResponseEntity getSubjectList(){
      List<OneSubject> subjectList  = subjectService.getSubjectList();
      return ResponseEntity.ok().data("list",subjectList);
    }

}

